package com.zhuiyun.project.api.ancientPoetry.controller;

import com.zhuiyun.project.annotation.OptLog;
import com.zhuiyun.project.api.ancientPoetry.entity.AncientPoetry;
import com.zhuiyun.project.api.ancientPoetry.model.AncientPoetryModel;
import com.zhuiyun.project.api.ancientPoetry.service.AncientPoetryService;
import com.zhuiyun.project.api.monitor.domain.server.Sys;
import com.zhuiyun.project.common.controller.BaseController;
import com.zhuiyun.project.common.errorCode.CommonException;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.constants.CommonConstants;
import com.zhuiyun.project.utils.pageUtil.PageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @Description TODO 诗词管理
 * @Author shy
 * @Date 2023/12/6 15:55
 */
@RestController
@RequestMapping("AncientPoetry")
@Api(tags = "诗词管理模块")
public class AncientPoetryController extends BaseController {
    @Autowired
    private AncientPoetryService ancientPoetryService;
    /**
     *
     * @Author shy
     * @Date 2023/12/7 11:47 TODO 分页查询诗词
      * @param ancientPoetryModel
     * @return CommonResult
     */
    @GetMapping("listPoetry")
    @OptLog(modular = "诗词管理", type = CommonConstants.SELECT, describe = "查询诗词")
    @ApiOperation(value = "分页查询诗词")
    public CommonResult PageListPoetry(AncientPoetryModel ancientPoetryModel, PageRequest pageRequest){
        return ancientPoetryService.PageListPoetry(ancientPoetryModel,pageRequest);
    }

    /**
     *
     * @Author shy
     * @Date 2023/12/7 15:31 TODO 本地添加诗
      * @param path   本地文本存储的地址
     * 文本样式：Json类型
     *   最后一个文本必须要少一括号
     *   例：[{"author": "","paragraphs": "","title": ""},{},{]
     *
     */
    @GetMapping("URLInsert")
    @OptLog(modular = "诗词管理", type = CommonConstants.ADD, describe = "从本地新增数据")
    @ApiOperation(value = "本地添加诗词")
    public void URLInsert (String path) throws IOException {
        ancientPoetryService.URLInsert(path);
    }
    /**
     *
     * @Author shy
     * @Date 2023/12/7 15:44 TODO 根据id删除诗词
      * @param id
     * @return CommonResult
     */
    @DeleteMapping("deletePoetry")
    @OptLog(modular = "诗词管理",type = CommonConstants.DELETE,describe = "删除诗词")
    @ApiOperation(value = "删除诗词")
    public CommonResult DeletePoetry(Integer id){
        return ancientPoetryService.DeletePoetry(id);
    }

    /**
     *
     * @Author shy TODO  添加诗词
     * @Date 2023/12/8 11:04
      * @param ancientPoetryModel
     * @return CommonResult
     */
    @PostMapping("insertPoetry")
    @OptLog(modular = "诗词管理",type = CommonConstants.ADD,describe = "添加诗词")
    @ApiOperation(value = "添加诗词")
    public CommonResult insertPoetry(AncientPoetryModel ancientPoetryModel) throws CommonException {
        return ancientPoetryService.insertPoetry(ancientPoetryModel);
    }
    /**
     *
     * @Author shy
     * @Date 2023/12/14 10:50 TODO 修改诗词
      * @param ancientPoetryModel
     * @return CommonResult
     */
    @PostMapping("updatePoetry")
    @OptLog(modular = "诗词管理",type = CommonConstants.UPDATE,describe = "更新诗词")
    @ApiOperation(value = "更新诗词")
    public CommonResult updatePoetry(AncientPoetryModel ancientPoetryModel) throws CommonException {
        return ancientPoetryService.updatePoetry(ancientPoetryModel);
    }
}